package interview.maxsubarraysum;

public class MaxSubarraySum {
	public int run(int[] array) {
		int index = 0;
		while(array[index] < 0) {
			index++;
		}
		int maxSum = array[index];
		int temp = maxSum;
		index++;
		while(index < array.length) {
			temp += array[index];
			if(temp > maxSum) {
				maxSum = temp;
			} else if (temp < 0) {
				temp = 0;
			}
			index++;
		}
		
		return maxSum;
	}
}
